package com.bbzn.user.client.controller;

import com.bbzn.user.client.constant.ChangeConstant;
import com.bbzn.user.client.utils.QRCodeUtil;
import com.google.zxing.Result;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

import javax.servlet.http.HttpServletRequest;
/**
 * @Author wulongbo
 * @Date 2020/8/8 14:14
 * @Version 1.0
 */

/**
 * 二维码调用前端控制器
 */
@RequestMapping("/qrcode")
@Controller
public class QrcodeController {


    /**
     * 生成二维码
     */
    @GetMapping(value = "/productcode1")
    public void productcode1(HttpServletRequest request) {
        String agent = request.getHeader("user-agent");
        String url = "";
        if (agent.contains("Android")) {
            //是否是安卓系统
            System.out.println(" 是安卓系统");
            url = "http://39.102.56.91:81/baba1.0.19_1019_jiagu_sign.apk";
        }
        if (agent.contains("iPhone") || agent.contains("iPod") || agent.contains("iPad")) {
            System.out.println(" 是苹果系统");
            url = "http://39.102.56.91:81/baba1.0.19_1019_jiagu_sign.apk";
        }
        if (agent.contains("MI")) {
            //小米
            url = "http://39.102.56.91:81/baba1.0.19_1019_jiagu_sign.apk";
        }

        if (agent.contains("lenovo")) {
            //联想
            url = "http://39.102.56.91:81/baba1.0.19_1019_jiagu_sign.apk";
        }
        url = "http://39.102.56.91:81/baba1.0.19_1019_jiagu_sign.apk";
    }


    /**
     * 重定向
     */
    @RequestMapping(value = "/getUrl")
    public ModelAndView productcode(HttpServletRequest request) {
        String agent = request.getHeader("user-agent");
        String url = ChangeConstant.ANDROID;
        if (agent.contains("Android")) {
            //是否是安卓系统
            System.out.println(" 是安卓系统");
            url = ChangeConstant.ANDROID;
        }
        if (agent.contains("iPhone") || agent.contains("iPod") || agent.contains("iPad")) {
            System.out.println(" 是苹果系统");
            url = ChangeConstant.IOS;
        }
        if (agent.contains("MI")) {
            //小米
            url = ChangeConstant.ANDROID;
        }
        if (agent.contains("lenovo")) {
            //联想
            url = ChangeConstant.ANDROID;
        }
//        ModelAndView mv = new ModelAndView();
        return new ModelAndView(new RedirectView(url));
    }


    /**
     * 生成二维码
     */
    @GetMapping
    public void productcode() {

//        QRCodeUtil.zxingCodeCreate("http://39.102.56.91:81/baba1.0.19_1019_jiagu_sign.apk", "D:/voice/picture/2018/",500,"D:/voice/picture/2018/picture.png");
        QRCodeUtil.zxingCodeCreate("https://www.babazhn.com/", "D:/voice/picture/2018/", 500, "D:/voice/picture/2018/6.png");//http://269n5m9544.qicp.vip

    }


    /**
     * 解析二维码
     */
    @GetMapping("/test")
    public void analysiscode() {
        Result result = QRCodeUtil.zxingCodeAnalyze("D:/voice/picture/2018/759.jpg");
        System.err.println("二维码解析内容：" + result.toString());
    }


}
